package com.book.lizhi.read;

import java.util.Vector;

import android.content.Context;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.book.lizhi.R;

public class ReadView extends RelativeLayout implements Callback {

	private ShowTextView mCurrentView;
	private ShowTextView mNextView;
	// private TestShowTextView mPreView;

	private Handler mHandler;

	public Vector<String> vector;

	public ReadView(Context context, Paint paint) {
		super(context);
		mCurrentView = new ShowTextView(context, paint, getResources().getColor(R.color.read_color));
		mNextView = new ShowTextView(context, paint, getResources().getColor(R.color.read_color));

		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		addView(mNextView, params);
		addView(mCurrentView, params);

		mHandler = new Handler(this);
	}

	public ReadView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void setTextSize(float textSize) {
		mCurrentView.setTextSize(textSize);
		mNextView.setTextSize(textSize);
	}

	public void setPaint(Paint paint) {
		mCurrentView.setPaint(paint);
		mNextView.setPaint(paint);
	}

	public void setBackgroudColor(int color) {
		// mPreView.setBackgroud(color);
		mCurrentView.setBackgroud(color);
		mNextView.setBackgroud(color);
		super.setBackgroundColor(color);
	}

	public Paint getPaint() {
		return mCurrentView.getPaint();
	}

	public int getLineHeight() {
		return mCurrentView.getLineHeight();
	}

	public void setCurrentText(Vector<String> strings) {
		vector = strings;
		mCurrentView.setText(strings);
		mCurrentView.resetPosition();
		mCurrentView.bringToFront();
	}

	public void setNextText(Vector<String> strings) {
		vector = strings;
		mNextView.setText(strings);
		mNextView.resetPosition();
		mCurrentView.bringToFront();
	}

	public void nextMove(int x, int y) {
		mCurrentView.bringToFront();
		mCurrentView.scrollTo(x, y);
	}

	public void setPreText(Vector<String> strings) {
		vector = strings;
		mNextView.setText(strings);
	}

	public void preMove(int x, int y) {
		mNextView.bringToFront();
		mNextView.scrollTo(x, y);
	}

	public void preScroll(float x, float y) {
		mNextView.preScroll((int) x, (int) y);
		ShowTextView temp = mCurrentView;
		mCurrentView = mNextView;
		mNextView = temp;
	}

	public void nextScroll(float x, float y) {
		mCurrentView.nextScroll((int) x, (int) y);
		ShowTextView temp = mCurrentView;
		mCurrentView = mNextView;
		mNextView = temp;
		mHandler.sendEmptyMessageDelayed(0, 100);
	}

	@Override
	public boolean handleMessage(Message msg) {
		mCurrentView.bringToFront();
		return true;
	}

	public void setTextPaint(Paint paint) {

	}

}
